package com.huangpuweb.api.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huangpuweb.api.model.*;
import com.huangpuweb.api.service.*;
import com.huangpuweb.api.util.CaculateDistanceTest;
import com.huangpuweb.api.util.DateUtil;
import com.huangpuweb.api.util.MapUtil;
import com.huangpuweb.api.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.log4j.Logger;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 公共安全模块
 */
@Controller
@RequestMapping(value = "/emergency")
public class GongGongAnQuanController {

    private static Logger logger = Logger.getLogger(GongGongAnQuanController.class);

    private GongGongAnQuanApiService gongGongAnQuanApiService;

    @Autowired
    public void setGongGongAnQuanApiService(GongGongAnQuanApiService gongGongAnQuanApiService) {
        this.gongGongAnQuanApiService = gongGongAnQuanApiService;
    }


    private GongGongAnQuanApiSysDataService gongGongAnQuanApiSysDataService;

    @Autowired
    public void setGongGongAnQuanApiSysDataService(GongGongAnQuanApiSysDataService gongGongAnQuanApiSysDataService) {
        this.gongGongAnQuanApiSysDataService = gongGongAnQuanApiSysDataService;
    }


    private XuJianApiService xuJianApiService;

    @Autowired
    public void setXuJianApiService(XuJianApiService xuJianApiService) {
        this.xuJianApiService = xuJianApiService;
    }

    @Resource
    private PersonDataService personDataService;
    @Resource
    private CrowdSituationApiService crowdSituationApiService;

    @Autowired
    private MetroService metroService;

    /**
     * 垃圾视频点位事件
     */
    @RequestMapping(value = "/getListRubbishEventByVideo")
    public void getListRubbishEventByVideo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();

        String str = getRequestBodyString(req);
        JSONObject reqjson = JSONObject.parseObject(str);

        //事件图片的url
        String cameraid = reqjson.getString("cameraid");


        List<SysHpLjEventData> listEvent = gongGongAnQuanApiSysDataService.getListSysHpLjEventDataByCameraid(cameraid);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listEvent);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 垃圾监测事件
     */
    @RequestMapping(value = "/getListRubbishEvent")
    public void getListRubbishEvent(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getListRubbishEvent-----start-------");
        List<SysHpLjEventData> listEvent = gongGongAnQuanApiSysDataService.getListSysHpLjEventData();

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listEvent);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 垃圾监测视频点位数据
     */
    @RequestMapping(value = "/getListRubbishVideo")
    public void getListRubbishVideo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getListRubbishVideo-----start-------");
        List<SysHpLjPublicVideo> listvideo = gongGongAnQuanApiSysDataService.getListSysHpLjPublicVideo();

        for (SysHpLjPublicVideo s : listvideo) {
            Integer eventcount = 0;
            eventcount = gongGongAnQuanApiSysDataService.getLjVideoEventCountByCameraId(s.getCamera_id());
            s.setEventcount(eventcount);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listvideo);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 应急资源-物资
     */
    @RequestMapping(value = "/getWuZiByEnercy")
    public void getWuZiByEnercy(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getWuZiByEnercy-----start-------");
        List<SysHpXiaoFangAjType> listWuzi = xuJianApiService.getListWuziByEnercy();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listWuzi);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 消防微型防站数据
     */
    @RequestMapping(value = "/getFireControlStationList")
    public void getFireControlStationList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getFireControlStationList-----start-------");


        List<SysMiniFireControl> weixinstation = gongGongAnQuanApiSysDataService.getListFireControlStaitionByType("微型消防站");
        List<SysMiniFireControl> importstation = gongGongAnQuanApiSysDataService.getListFireControlStaitionByType("重点单位");
        List<SysStreetFireInfo> streetstation = gongGongAnQuanApiSysDataService.getListFireControlStreetStation();


        for (SysMiniFireControl ss : weixinstation) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
            ss.setLng(map[0] + "");
            ss.setLat(map[1] + "");
        }


        for (SysMiniFireControl ss : importstation) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
            ss.setLng(map[0] + "");
            ss.setLat(map[1] + "");
        }


        for (SysStreetFireInfo ss : streetstation) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
            ss.setLng(map[0] + "");
            ss.setLat(map[1] + "");
        }

        resultJson.put("weixinstation", weixinstation);
        resultJson.put("importstation", importstation);
        resultJson.put("streetstation", streetstation);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 图层数据
     */
    @RequestMapping(value = "/getMapEventItem")
    public void getMapEventItem(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getMapEventItem-----start-------");
        JSONObject fangtaifangxunjsonObject = new JSONObject();
        JSONObject evnetjsonObject = new JSONObject();

        //市政下立交视频
        Integer overpasscount = gongGongAnQuanApiSysDataService.getOverPassCount();
        //抢险队伍
        Integer teamcount = gongGongAnQuanApiSysDataService.listSysHpEmergencyTeamCount();
        //重大险情
        Integer dangercount = gongGongAnQuanApiSysDataService.listSysHpEmergencyDangerCount();
        //撤离点
        Integer refugecount = gongGongAnQuanApiSysDataService.listSysHpEmergencyRefugeCount();
        //中考防汛点
        Integer protectcount = gongGongAnQuanApiSysDataService.listSysHpEmergencyProtectCount();
        //微型泵站
        Integer waterenginecount = gongGongAnQuanApiSysDataService.listSysHpEmergencyWaterengineCount("小包围设施");
        //大型泵站
        Integer largeWaterenginecount = gongGongAnQuanApiSysDataService.listSysHpEmergencyWaterengineCount("市级");
        //年度事件数
        Integer yearEventCount = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEventCount(DateUtil.getCurrYearFirst());
        //消防站数
        Integer firecontrolCount = gongGongAnQuanApiSysDataService.getListFireControlCount();
        //重点区域-地铁
        Integer importareasubwaycount = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaCount("1");
        //重点区域-隧道
        Integer importareasuidaocount = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaCount("3");
        //重点区域-立交
        Integer importarealijiaocount = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaCount("2");
        //闸门数据
        Integer zhamencount = gongGongAnQuanApiSysDataService.listZhaMenCount();


        evnetjsonObject.put("yearEventCount", yearEventCount);
        fangtaifangxunjsonObject.put("overpasscount", overpasscount);
        fangtaifangxunjsonObject.put("teamcount", teamcount);
        fangtaifangxunjsonObject.put("importareacount", importareasubwaycount);
        fangtaifangxunjsonObject.put("importareasuidaocount", importareasuidaocount);
        fangtaifangxunjsonObject.put("zhamencount", zhamencount);
        fangtaifangxunjsonObject.put("importarealijiaocount", importarealijiaocount);
        fangtaifangxunjsonObject.put("dangercount", dangercount);
        fangtaifangxunjsonObject.put("refugecount", refugecount);
        fangtaifangxunjsonObject.put("protectcount", protectcount);
        fangtaifangxunjsonObject.put("waterenginecount", waterenginecount);
        fangtaifangxunjsonObject.put("largeWaterenginecount", largeWaterenginecount);
        fangtaifangxunjsonObject.put("historycount", "历史沿革");
        fangtaifangxunjsonObject.put("firecontrolCount", firecontrolCount);
        resultJson.put("evnetjsonObject", evnetjsonObject);
        resultJson.put("fangtaifangxunjsonObject", fangtaifangxunjsonObject);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 市政下立交视频
     */
    @RequestMapping(value = "/getAllOverPassControl")
    public void getAllOverPassControl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllOverPassControl-----start-------");
        List<SysOverPassControl> listSysOverPassControl = gongGongAnQuanApiSysDataService.listSysOverPassControl();
        for (SysOverPassControl ss : listSysOverPassControl) {
            if (StringUtils.isNotEmpty(ss.getLng())) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
                ss.setLng(map[0] + "");
                ss.setLat(map[1] + "");
            }

        }
        resultJson.put("listSysHpEmergencyZhaMen", listSysOverPassControl);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 闸门数据
     */
    @RequestMapping(value = "/getAllEmergencyZhaMen")
    public void getAllEmergencyZhaMen(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyZhaMen-----start-------");
        List<SysHpEmergencyZhaMen> listSysHpEmergencyZhaMen = gongGongAnQuanApiSysDataService.listSysHpEmergencyZhaMen();
        for (SysHpEmergencyZhaMen ss : listSysHpEmergencyZhaMen) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyZhaMen", listSysHpEmergencyZhaMen);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 消防站数
     */
    @RequestMapping(value = "/getAllEmergencyFireControlStation")
    public void getAllEmergencyFireControlStation(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyFireControlStation-----start-------");
        List<SysHpEmergencyFireControl> listSysHpEmergencyFireControl = gongGongAnQuanApiSysDataService.listSysHpEmergencyFireControl();
        for (SysHpEmergencyFireControl ss : listSysHpEmergencyFireControl) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyFireControl", listSysHpEmergencyFireControl);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 防台防汛专业队伍获取
     */
    @RequestMapping(value = "/getAllEmergencyEventTeam")
    public void getAllEmergencyEventTeam(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventTeam-----start-------");
        List<SysHpEmergencyTeam> listSysHpEmergencyTeam = gongGongAnQuanApiSysDataService.listSysHpEmergencyTeamByType(1);
        for (SysHpEmergencyTeam ss : listSysHpEmergencyTeam) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyTeam", listSysHpEmergencyTeam);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 防台防汛重点区域数据 立交
     */
    @RequestMapping(value = "/getAllEmergencyEventLijiao")
    public void getAllEmergencyEventLijiao(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventLijiao-----start-------");
        List<SysHpEmergencyImportArea> listSysHpEmergencyImportArea = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaByType(2);
        for (SysHpEmergencyImportArea ss : listSysHpEmergencyImportArea) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyImportArea", listSysHpEmergencyImportArea);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 防台防汛重点区域数据 隧道
     */
    @RequestMapping(value = "/getAllEmergencyEventSuiDao")
    public void getAllEmergencyEventSuiDao(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventSuiDao-----start-------");
        List<SysHpEmergencyImportArea> listSysHpEmergencyImportArea = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaByType(3);
        for (SysHpEmergencyImportArea ss : listSysHpEmergencyImportArea) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyImportArea", listSysHpEmergencyImportArea);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 防台防汛重点区域数据 地铁
     */
    @RequestMapping(value = "/getAllEmergencyEventSubway")
    public void getAllEmergencyEventSubway(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventTeam-----start-------");
        List<SysHpEmergencyImportArea> listSysHpEmergencyImportArea = gongGongAnQuanApiSysDataService.listSysHpEmergencyImportAreaByType(1);
        TblMetroInout tblMetroInout = new TblMetroInout();
        tblMetroInout.setStmtDay(DateUtil.getDateFormat());
        //当天累计地铁进出口总数
        List<TblMetroInout> tblMetroInoutList = metroService.getTblMetroInoutList(tblMetroInout);
        for (SysHpEmergencyImportArea ss : listSysHpEmergencyImportArea) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
            //匹配地铁站客流量
            for(TblMetroInout tblMetroInout1 : tblMetroInoutList){
                if(ss.getAreaName().equals(tblMetroInout1.getStationNmCn())){
                    ss.setInSum(tblMetroInout1.getInSum());
                    ss.setOutSum(tblMetroInout1.getOutSum());
                    break;
                }
            }
        }


        resultJson.put("listSysHpEmergencyImportArea", listSysHpEmergencyImportArea);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 防台防汛重大险情
     */
    @RequestMapping(value = "/getAllEmergencyEventDanger")
    public void getAllEmergencyEventDanger(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventDanger-----start-------");
        List<SysHpEmergencyDanger> listSysHpEmergencyDanger = gongGongAnQuanApiSysDataService.llistSysHpEmergencyDangerByType(1);
        for (SysHpEmergencyDanger ss : listSysHpEmergencyDanger) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyDanger", listSysHpEmergencyDanger);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 防台防汛撤离点信息
     */
    @RequestMapping(value = "/getAllEmergencyEventSafePlace")
    public void getAllEmergencyEventSafePlace(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventSafePlace-----start-------");
        List<SysHpEmergencyRefuge> listSysHpEmergencyRefuge = gongGongAnQuanApiSysDataService.llistSysHpEmergencyRefugeByType(1);
        for (SysHpEmergencyRefuge ss : listSysHpEmergencyRefuge) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyRefuge", listSysHpEmergencyRefuge);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 防台防汛中考防汛
     */
    @RequestMapping(value = "/getAllEmergencyEventPortect")
    public void getAllEmergencyEventPortect(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventPortect-----start-------");
        List<SysHpEmergencyProtect> listSysHpEmergencyProtect = gongGongAnQuanApiSysDataService.llistSysHpEmergencyProtectByType(1);
        for (SysHpEmergencyProtect ss : listSysHpEmergencyProtect) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }
        resultJson.put("listSysHpEmergencyProtect", listSysHpEmergencyProtect);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 防台防汛泵站-小包围
     */
    @RequestMapping(value = "/getAllEmergencyEventWaterEngine")
    public void getAllEmergencyEventWaterEngine(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventWaterEngine-----start-------");
        List<SysHpEmergencyWaterengine> listSysHpEmergencyWaterengine = gongGongAnQuanApiSysDataService.llistSysHpEmergencyWaterengineByType(1, "小包围设施");
        for (SysHpEmergencyWaterengine ss : listSysHpEmergencyWaterengine) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }

        resultJson.put("listSysHpEmergencyWaterengine", listSysHpEmergencyWaterengine);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }


    /**
     * 防台防汛大型泵站
     */
    @RequestMapping(value = "/getAllEmergencyEventlargeWater")
    public void getAllEmergencyEventlargeWater(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventlargeWater-----start-------");
        List<SysHpEmergencyWaterengine> listSysHpEmergencyWaterengine = gongGongAnQuanApiSysDataService.llistSysHpEmergencyWaterengineByType(1, "市级");
        for (SysHpEmergencyWaterengine ss : listSysHpEmergencyWaterengine) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getBaiduLongitude()), Double.parseDouble(ss.getBaiduLatitude()));
            ss.setBaiduLongitude(map[0] + "");
            ss.setBaiduLatitude(map[1] + "");
        }

        resultJson.put("listSysHpEmergencyWaterengine", listSysHpEmergencyWaterengine);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 全区事件分析
     */
    @RequestMapping(value = "/getAllEmergencyEvent")
    public void getAllEmergencyEvent(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEvent-----start-------");
        Date baseYear = DateUtil.getCurrYearFirst();
        Integer listSysHpEmergencyEventCount = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEventCountByYear(baseYear);

        resultJson.put("alleventcount", listSysHpEmergencyEventCount);
        resultJson.put("yeseventcount", listSysHpEmergencyEventCount);
        resultJson.put("noeventcount", 0);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }


    /**
     * 全区事件分析 第二版本
     */
    @RequestMapping(value = "/getAllEmergencyEventV2")
    public void getAllEmergencyEventV2(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllEmergencyEventV2-----start-------");
        Date baseYear = DateUtil.getCurrYearFirst();
        //事件总数
        Integer listSysHpEmergencyEventCount = xuJianApiService.getListSysHpEmergencyEventCountByYear(baseYear);
        //当月数量
        Integer nowMonth = xuJianApiService.getNowMonth();
        //当日数量
        Integer today = xuJianApiService.getToday();
        //已处置
        Integer listSysHasHpEmergencyEventCount = xuJianApiService.getListHasSysHpEmergencyEventCountByYear(baseYear);

        List<SysHpXiaoFangAjType> listType = xuJianApiService.getListEmergencyType(baseYear);

        //自然灾害
        Integer a = 127;
        //事故灾难
        Integer a1 = 514;
        //社会安全
        Integer b = 211;
        //公共卫生
        Integer c = 23;
        //其他
        Integer d = 1868;
        Integer aBase = 0;
        Integer a1Base = 0;
        Integer bBase = 0;
        Integer cBase = 0;
        Integer dBase = 0;

        JSONObject typejson = new JSONObject();
        for (SysHpXiaoFangAjType s : listType) {
            if (s.getKind_name().equals("自然灾害")) {
                aBase = aBase + 1;

            }
            if (s.getKind_name().equals("公共卫生")) {
                cBase = cBase + 1;
            }
            if (s.getKind_name().equals("社会安全")) {
                bBase = bBase + 1;
            }
            if (s.getKind_name().equals("其他")) {
                dBase = dBase + 1;
            }
            if (s.getKind_name().equals("事故灾难")) {
                a1Base = a1Base + 1;
            }
        }
        typejson.put("自然灾害", a + aBase);
        typejson.put("事故灾难", a1 + a1Base);
        typejson.put("社会安全", b + bBase);
        typejson.put("公共卫生", c + cBase);
        typejson.put("其他", d + dBase);


        JSONObject baseyearjson = new JSONObject();
        baseyearjson.put("自然灾害", aBase);
        baseyearjson.put("社会安全", bBase);
        baseyearjson.put("公共卫生", cBase);
        baseyearjson.put("事故灾难", a1Base);
        baseyearjson.put("其他", dBase);

        JSONObject yearArray = new JSONObject();

        JSONObject yearjson = new JSONObject();
//        yearjson.put("应急", 59);
//        yearjson.put("社会安全", 25);
//        yearjson.put("公共卫生", 1);
//        yearjson.put("其他", 79);
//        yearArray.put("2016", yearjson);

        yearjson = new JSONObject();
        yearjson.put("自然灾害", 1);
        yearjson.put("事故灾难", 112);
        yearjson.put("社会安全", 45);
        yearjson.put("公共卫生", 7);
        yearjson.put("其他", 437);
        yearArray.put("2017", yearjson);

        yearjson = new JSONObject();
        yearjson.put("自然灾害", 28);
        yearjson.put("事故灾难", 90);
        yearjson.put("社会安全", 66);
        yearjson.put("公共卫生", 0);
        yearjson.put("其他", 401);
        yearArray.put("2018", yearjson);

        yearjson = new JSONObject();
        yearjson.put("自然灾害", 76);
        yearjson.put("事故灾难", 113);
        yearjson.put("社会安全", 47);
        yearjson.put("公共卫生", 2);
        yearjson.put("其他", 474);
        yearArray.put("2019", yearjson);


        yearjson = new JSONObject();
        yearjson.put("自然灾害", 22);
        yearjson.put("事故灾难", 147);
        yearjson.put("社会安全", 34);
        yearjson.put("公共卫生", 14);
        yearjson.put("其他", 488);
        yearArray.put("2020", yearjson);


        resultJson.put("alleventcount", listSysHpEmergencyEventCount);
        resultJson.put("yeseventcount", listSysHasHpEmergencyEventCount);
        resultJson.put("nowMonth", nowMonth);
        resultJson.put("today", today);

        resultJson.put("typejson", typejson);
        resultJson.put("baseyearjson", baseyearjson);
        resultJson.put("yearjson", yearArray);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }


    /**
     * 公共安全模块-Top5事件列表 第二版本
     * hp_emergency_event
     */
    @RequestMapping(value = "/getTop5EventListV2")
    public void getTop5EventListV2(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        // 创建HttpClient实例
        HttpClient client = HttpClientBuilder.create().build();
        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        JSONObject locationjson = null;
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getTop5EventListV2-----start-------");
        List<XJEvent> listSysHpEmergencyEvent = xuJianApiService.getListSysHpEmergencyEvent();
        String eventType = "";
        for (XJEvent xj : listSysHpEmergencyEvent) {
            //根据type查询 name
            String eventcatename = xuJianApiService.getEventCateNameById(xj.getEvent_cate());
            xj.setEvent_cate_desc(eventcatename);
            if (StringUtils.isNotEmpty(xj.getEvent_gis())) {
                String[] str = xj.getEvent_gis().split(",");
                xj.setBaiduLongitude(str[0] + "");
                xj.setBaiduLatitude(str[1] + "");

            }

        }
        resultJson.put("listSysHpEmergencyEvent", listSysHpEmergencyEvent);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 本年度事件发生趋势 按月份
     */
    @RequestMapping(value = "/getEmergencyEventCountByMonth")
    public void getEmergencyEventCountByMonth(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyEventCountByMonth-----start-------");
        Date baseYear = DateUtil.getCurrYearFirst();
        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEventByYear(baseYear);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, Integer> houMap = new HashMap<String, Integer>();
        for (SysHpEmergencyEvent oness : listSysHpEmergencyEvent) {

            try {
                if (oness.getStartTime() != null) {
                    String createTime = sdf.format(oness.getStartTime());
                    String month = DateUtil.getMonth(createTime);

                    if (StringUtil.isNotEmpty(month)) {
                        if (Integer.parseInt(month) >= 1 && Integer.parseInt(month) <= 12) {
                            if (houMap.get(month) != null) {
                                houMap.put(month, houMap.get(month) + 1);
                            } else {
                                houMap.put(month, 1);
                            }
                        }

                    }
                }
            } catch (Exception e) {
                continue;
            }


        }

        JSONArray ssArray = new JSONArray();
        JSONObject ssjson = null;
        Boolean flag = false;
        for (Map.Entry<String, Integer> entry : houMap.entrySet()) {
            ssjson = new JSONObject();
            //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
            ssjson.put("time", entry.getKey());
            ssjson.put("value", entry.getValue());
            ssArray.add(ssjson);

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ssArray);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 本年度事件发生趋势 按事件类型
     */
    @RequestMapping(value = "/getEmergencyEventCountByType")
    public void getEmergencyEventCountByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyEventCountByType-----start-------");
        Date baseYear = DateUtil.getCurrYearFirst();
        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEventByYear(baseYear);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, Integer> houMap = new HashMap<String, Integer>();
        for (SysHpEmergencyEvent oness : listSysHpEmergencyEvent) {

            if (oness.getEventType().equals("290ef77a-7c02-41c1-a279-5e2ce0a45340")) {

                oness.setEventType("事故灾难");

            } else if (oness.getEventType().equals("3d93e3d7-ba1d-4442-b825-44333b66290a")) {
                oness.setEventType("其他");
                //1e1b5957-5818-4a0f-8f99-eb9ce46b3e51
            } else if (oness.getEventType().equals("1e1b5957-5818-4a0f-8f99-eb9ce46b3e51")) {
                //eventType = "自然灾害";
                oness.setEventType("自然灾害");

            } else if (oness.getEventType().equals("348be4c1-46ea-47c1-a0c8-2c7175a7a890")) {
//                eventType = "社会安全";
                oness.setEventType("社会安全");

            } else if (oness.getEventType().equals("2b80b610-461c-4389-bf61-49ba17b85f0d")) {
//                eventType = "公共卫生";
                oness.setEventType("公共卫生");

            }
            if (oness.getEventType().length() > 7) {
                if (houMap.get("其他") != null) {
                    houMap.put("其他", houMap.get("其他") + 1);
                } else {
                    houMap.put("其他", 1);
                }
                continue;
            }
            if (houMap.get(oness.getEventType()) != null) {

                houMap.put(oness.getEventType(), houMap.get(oness.getEventType()) + 1);


            } else {
                houMap.put(oness.getEventType(), 1);
            }
        }

        JSONArray ssArray = new JSONArray();
        JSONObject ssjson = null;
        Boolean flag = false;
        for (Map.Entry<String, Integer> entry : houMap.entrySet()) {
            ssjson = new JSONObject();
            //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
            ssjson.put("type", entry.getKey());
            ssjson.put("value", entry.getValue());
            ssArray.add(ssjson);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ssArray);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 本年度事件发生趋势 按年查询
     */
    @RequestMapping(value = "/getEmergencyEventCountByYear")
    public void getEmergencyEventCountByYear(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyEventCountByYear-----start-------");
//        Date baseYear= DateUtil.getCurrYearFirst();
        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEventByMoreYear();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, Integer> houMap = new HashMap<String, Integer>();
        for (SysHpEmergencyEvent oness : listSysHpEmergencyEvent) {
            try {
                String createTime = sdf.format(oness.getStartTime());
                if (StringUtil.isNotEmpty(createTime)) {

                    String year = DateUtil.getYear(createTime);
                    if (year.substring(0, 2).equals("20")) {
                        if (houMap.get(year) != null) {
                            houMap.put(year, houMap.get(year) + 1);
                        } else {
                            houMap.put(year, 1);
                        }
                    }


                }
            } catch (Exception e) {
                continue;
            }


        }

        JSONArray ssArray = new JSONArray();
        JSONObject ssjson = null;
        Boolean flag = false;
        for (Map.Entry<String, Integer> entry : houMap.entrySet()) {
            ssjson = new JSONObject();
            //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
            ssjson.put("time", entry.getKey());
            ssjson.put("value", entry.getValue());
            ssArray.add(ssjson);

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ssArray);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 单个事件应急队伍类别
     */
    @RequestMapping(value = "/getEmergencyResourceXJTRescueTeamType")
    public void getEmergencyResourceXJTRescueTeamType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceXJTRescueTeamType-----start-------");


        List<String> listtype = xuJianApiService.getListEmergencyResourceXJTRescueTeamType();

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listtype);
        responseData(resultObj.toString(), resp);
    }


    @RequestMapping(value = "/getEmergencyResourceList")
    @ResponseBody
    public Object getEmergencyResourceList(HttpServletRequest req, HttpServletResponse resp) throws Exception{
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            resultObj.put("error_code", -1);
            resultObj.put("error_msg", "参数不能为空");
            return resultObj;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String typesTemp = jsonObject.getString("types");
        String types = typesTemp.replaceAll(",","|");
        String eventid = jsonObject.getString("eventid");
        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);
        String[] mag = xjEvent.getEvent_gis().split(",");
        //事件所处位置坐标
        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
        // 公共卫生 医疗救治  安全生产 应急抢修  自然灾害  社会安全  防台防汛
        //String types = "公共卫生|医疗救治|安全生产|应急抢修|自然灾害|社会安全|防台防汛";
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        List<XJTRescueTeam> listXJTRescueTeam = new ArrayList<>();
        if(!StringUtil.isEmpty(types)){
            listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByTypes(types);
            //根据坐标计算距离
            dealCoordinate(source, listXJTRescueTeam);
        }
        resultObj.put("data", listXJTRescueTeam);
        return resultObj;
    }



    /**
     * 单个事件周边协同应急队伍撒点(废弃)
     */
//    @RequestMapping(value = "/getEmergencyResourceList")
    @ResponseBody
  /*  public Object getEmergencyResourceList(HttpServletRequest req, HttpServletResponse resp) throws Exception{
        JSONObject resultObj = new JSONObject();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        List<XJTRescueTeam> listXJTRescueTeam = xuJianApiService.getListXJTRescueTeam();
        resultObj.put("data", listXJTRescueTeam);
        return resultObj;
    }*/


    /**
     * 单个事件周边协同应急队伍(废弃)
     */
    @RequestMapping(value = "/getEmergencyResourceXJTRescueTeam")
    public void getEmergencyResourceXJTRescueTeam(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceXJTRescueTeam-----start-------");


        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String eventid = jsonObject.getString("eventid");
        String area = jsonObject.getString("area");
        String type = jsonObject.getString("type");

        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);

        String[] mag = xjEvent.getEvent_gis().split(",");
        //事件所处位置坐标
        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
        GlobalCoordinates target = null;
        List<XJTRescueTeam> listXJTRescueTeam = null;
        //协同应急队伍
        if (StringUtils.isNotEmpty(type)) {
            listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType(type);
        } else {
            listXJTRescueTeam = xuJianApiService.getListXJTRescueTeam();
        }
//        List<XJTRescueTeam> newlistXJTRescueTeam = new ArrayList<XJTRescueTeam>();
//        if (listXJTRescueTeam != null && listXJTRescueTeam.size() > 0) {
//            //应急场所
//            for (XJTRescueTeam xj : listXJTRescueTeam) {
//                if (StringUtil.isNotEmpty(xj.getTeam_gis())) {
//                    mag = xj.getTeam_gis().split(",");
//                    target = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
//                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
//                    xj.setMeter(meter);
//                    newlistXJTRescueTeam.add(xj);
//                }
//
//
//            }
//        }
        //应急队伍
        //公共卫生
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("公共卫生");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listAnQuan", listXJTRescueTeam);
        //医疗救治
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("医疗救治");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listYiliaoJiuZhi", listXJTRescueTeam);
        //安全生产
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("安全生产");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listShenCan", listXJTRescueTeam);
        //应急抢修
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("应急抢修");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listYiJiQiangxiu", listXJTRescueTeam);
        //自然灾害
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("自然灾害");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listZiRan", listXJTRescueTeam);
        //社会安全
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("社会安全");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listSheHuiAnQuan", listXJTRescueTeam);
        //防台防汛
        listXJTRescueTeam = xuJianApiService.getListXJTRescueTeamByType("防台防汛");
        //根据坐标计算距离
        dealCoordinate(source, listXJTRescueTeam);
        resultJson.put("listFangTaiFangXun", listXJTRescueTeam);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 根据坐标计算距离
     * source --事件所在位置
     *
     */
    private void dealCoordinate(GlobalCoordinates source, List<XJTRescueTeam> listXJTRescueTeam){
        String[] mag = null;
        GlobalCoordinates target = null;
        if (listXJTRescueTeam != null && listXJTRescueTeam.size() > 0) {
            //应急场所
            for (XJTRescueTeam xj : listXJTRescueTeam) {
                if (StringUtil.isNotEmpty(xj.getTeam_gis())) {
                    mag = xj.getTeam_gis().split(",");
                    target = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }
            }
        }
    }

    /**
     * 单个事件周边协同应急场所
     */
    @RequestMapping(value = "/getEmergencyResourceXJTShelter")
    public void getEmergencyResourceXJTShelter(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceXJTShelter-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String eventid = jsonObject.getString("eventid");

        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);
        if (xjEvent != null) {
            String[] mag = xjEvent.getEvent_gis().split(",");
            GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
            GlobalCoordinates target = null;
            List<XJTShelter> listXJTShelter = xuJianApiService.getListXJTShelter();
//            List<HpBMedical> hospitalShelter = personDataService.getHospitalShelter();
            List<HpBMedical> hospitalShelter =crowdSituationApiService.getHospitalShelter();
            if (hospitalShelter != null && listXJTShelter.size() > 0) {
                for (HpBMedical hpBMedical : hospitalShelter) {
                    target = new GlobalCoordinates(Double.parseDouble(hpBMedical.getPOINT_Y()), Double.parseDouble(hpBMedical.getPOINT_X()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    hpBMedical.setMeter(meter);
                }
            }
            List<XJTShelter> newlistXJTShelter = new ArrayList<XJTShelter>();
            if (listXJTShelter != null && listXJTShelter.size() > 0) {
                //应急场所
                for (XJTShelter xj : listXJTShelter) {
                    if (StringUtil.isNotEmpty(xj.getShelter_lat())) {
                        target = new GlobalCoordinates(Double.parseDouble(xj.getShelter_lat()), Double.parseDouble(xj.getShelter_lon()));
                        double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                        xj.setMeter(meter);
                        newlistXJTShelter.add(xj);
                    }
                }
            }
            //应急队伍
            resultJson.put("listXJTShelter", newlistXJTShelter);
            //医疗机构
            resultJson.put("hospital", hospitalShelter);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }

    @Resource
    private SanitationService sanitationService;

    /**
     * 单个事件周边协同应急风险
     */
    @RequestMapping(value = "/getEmergencyResourceXJFengxian")
    public void getEmergencyResourceXJFengxian(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceXJFengxian-----start-------");


        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String eventid = jsonObject.getString("eventid");

        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);

        String[] mag = xjEvent.getEvent_gis().split(",");

        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
        GlobalCoordinates target = null;


        //风险隐患
        //第一点：重点危险源 T_FIREHYDRANT
        //第二点：积水点 T_EMER_PONDING
        List<XJTEmerPonding> listXJTEmerPonding = xuJianApiService.getListXJTEmerPonding();
        if (listXJTEmerPonding != null && listXJTEmerPonding.size() > 0) {
            //应急场所
            for (XJTEmerPonding xj : listXJTEmerPonding) {
                if (StringUtil.isNotEmpty(xj.getLat())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTEmerPonding", listXJTEmerPonding);

        //第三点：加油站 T_EMER_GAS_STATION

        List<XJTEmerGasStation> listXJTEmerGasStation = xuJianApiService.getListXJTEmerGasStation();
        if (listXJTEmerGasStation != null && listXJTEmerGasStation.size() > 0) {
            //应急场所
            for (XJTEmerGasStation xj : listXJTEmerGasStation) {
                if (StringUtil.isNotEmpty(xj.getLat())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }

        resultJson.put("listXJTEmerGasStation", listXJTEmerGasStation);
        List<SanitationInfo> FxdkList = crowdSituationApiService.getFxdkList();
        for (SanitationInfo sanitationInfo : FxdkList) {
            if (StringUtil.isNotEmpty(sanitationInfo.getLat())) {
                target = new GlobalCoordinates(Double.parseDouble(sanitationInfo.getLat()), Double.parseDouble(sanitationInfo.getLng()));
                double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                sanitationInfo.setMeter(meter);
            }
        }
        resultJson.put("FxdkList", FxdkList);

        //第四点：重要工程 T_TRANSPORT_COMPANY
        List<XJTTransportCompany> listXJTTransportCompany = xuJianApiService.getListXJTTransportCompany();
        if (listXJTTransportCompany != null && listXJTTransportCompany.size() > 0) {
            //应急场所
            for (XJTTransportCompany xj : listXJTTransportCompany) {
                if (StringUtil.isNotEmpty(xj.getCompany_gis())) {
                    mag = xj.getCompany_gis().split(",");
                    target = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTTransportCompany", listXJTTransportCompany);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 单个事件周边协同应急基础设施
     */
    @RequestMapping(value = "/getEmergencyResourceXJSheShi")
    public void getEmergencyResourceXJSheShi(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceXJSheShi-----start-------");


        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String eventid = jsonObject.getString("eventid");

        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);

        String[] mag = xjEvent.getEvent_gis().split(",");

        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
        GlobalCoordinates target = null;

        //基础设施
        //第一点：地铁站 T_EMER_SUBWAY_STATION
        List<XJTEmerSubwayStation> listXJTEmerSubwayStation = xuJianApiService.getListXJTEmerSubwayStation();
        if (listXJTEmerSubwayStation != null && listXJTEmerSubwayStation.size() > 0) {
            //应急场所
            for (XJTEmerSubwayStation xj : listXJTEmerSubwayStation) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTEmerSubwayStation", listXJTEmerSubwayStation);

        //第二点：隧道 T_EMER_TUNNEL

        List<XJTEmerTunnel> listXJTEmerTunnel = xuJianApiService.getListXJTEmerTunnel();
        if (listXJTEmerTunnel != null && listXJTEmerTunnel.size() > 0) {
            //应急场所
            for (XJTEmerTunnel xj : listXJTEmerTunnel) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTEmerTunnel", listXJTEmerTunnel);


        //第三点：地道 T_EMER_UNDERGROUND_PASSAGE
        List<XJTEmerUndergroundPassage> listXJTEmerUndergroundPassage = xuJianApiService.getListXJTEmerUndergroundPassage();
        if (listXJTEmerUndergroundPassage != null && listXJTEmerUndergroundPassage.size() > 0) {
            //应急场所
            for (XJTEmerUndergroundPassage xj : listXJTEmerUndergroundPassage) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTEmerUndergroundPassage", listXJTEmerUndergroundPassage);


        //第四点：物资仓库 T_EMER_WARE_HOUSE


        //第五点：下立交 T_EMER_CONCAVE_INTERCHANGE
        List<XJTEmerConcaveInterChange> listXJTEmerConcaveInterChange = xuJianApiService.getListXJTEmerConcaveInterChange();
        if (listXJTEmerConcaveInterChange != null && listXJTEmerConcaveInterChange.size() > 0) {
            //应急场所
            for (XJTEmerConcaveInterChange xj : listXJTEmerConcaveInterChange) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }
            }
        }
        resultJson.put("listXJTEmerConcaveInterChange", listXJTEmerConcaveInterChange);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 单个事件周边资源
     *
     * @param req
     * @param resp
     * @throws Exception
     */
    @RequestMapping(value = "/getEmergencyResourceV2")
    public void getEmergencyResourceV2(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceV2-----start-------");


        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String eventid = jsonObject.getString("eventid");
        String area = jsonObject.getString("area");


        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);

        String[] mag = xjEvent.getEvent_gis().split(",");

        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));


        List<XJTShelter> listXJTShelter = xuJianApiService.getListXJTShelter();
        GlobalCoordinates target = null;

//        if(listXJTShelter != null && listXJTShelter.size()>0){
//            //应急场所
//            for(XJTShelter xj:listXJTShelter){
//                if(StringUtil.isNotEmpty(xj.getShelter_lat())){
//                    target =new GlobalCoordinates(Double.parseDouble(xj.getShelter_lat()), Double.parseDouble(xj.getShelter_lon()));
//                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
//                    xj.setMeter(meter);
//                }
//
//
//            }
//        }

        //协同应急队伍
        List<XJTRescueTeam> listXJTRescueTeam = xuJianApiService.getListXJTRescueTeam();
//        if(listXJTRescueTeam != null && listXJTRescueTeam.size()>0){
//            //应急场所
//            for(XJTRescueTeam xj:listXJTRescueTeam){
//                if(StringUtil.isNotEmpty(xj.getTeam_gis())){
//                    mag=xj.getTeam_gis().split(",");
//                    target =new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
//                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
//                    xj.setMeter(meter);
//                }
//
//
//            }
//        }


        //风险隐患
        //第一点：重点危险源 T_FIREHYDRANT
        //第二点：积水点 T_EMER_PONDING
        List<XJTEmerPonding> listXJTEmerPonding = xuJianApiService.getListXJTEmerPonding();
        if (listXJTEmerPonding != null && listXJTEmerPonding.size() > 0) {
            //应急场所
            for (XJTEmerPonding xj : listXJTEmerPonding) {
                if (StringUtil.isNotEmpty(xj.getLat())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        //resultJson.put("listXJTEmerPonding",listXJTEmerPonding);

        //第三点：加油站 T_EMER_GAS_STATION

        List<XJTEmerGasStation> listXJTEmerGasStation = xuJianApiService.getListXJTEmerGasStation();
        if (listXJTEmerGasStation != null && listXJTEmerGasStation.size() > 0) {
            //应急场所
            for (XJTEmerGasStation xj : listXJTEmerGasStation) {
                if (StringUtil.isNotEmpty(xj.getLat())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        //resultJson.put("listXJTEmerGasStation",listXJTEmerGasStation);


        //第四点：重要工程 T_TRANSPORT_COMPANY
        List<XJTTransportCompany> listXJTTransportCompany = xuJianApiService.getListXJTTransportCompany();
        if (listXJTTransportCompany != null && listXJTTransportCompany.size() > 0) {
            //应急场所
            for (XJTTransportCompany xj : listXJTTransportCompany) {
                if (StringUtil.isNotEmpty(xj.getCompany_gis())) {
                    mag = xj.getCompany_gis().split(",");
                    target = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        resultJson.put("listXJTEmerFengxian", listXJTTransportCompany.size() + listXJTEmerGasStation.size() + listXJTEmerPonding.size());


        //应急队伍
        resultJson.put("listXJTRescueTeam", listXJTRescueTeam.size());
        //应急场所
        resultJson.put("listXJTShelter", listXJTShelter.size());


        //基础设施
        //第一点：地铁站 T_EMER_SUBWAY_STATION
        List<XJTEmerSubwayStation> listXJTEmerSubwayStation = xuJianApiService.getListXJTEmerSubwayStation();
        if (listXJTEmerSubwayStation != null && listXJTEmerSubwayStation.size() > 0) {
            //应急场所
            for (XJTEmerSubwayStation xj : listXJTEmerSubwayStation) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }


        //第二点：隧道 T_EMER_TUNNEL

        List<XJTEmerTunnel> listXJTEmerTunnel = xuJianApiService.getListXJTEmerTunnel();
        if (listXJTEmerTunnel != null && listXJTEmerTunnel.size() > 0) {
            //应急场所
            for (XJTEmerTunnel xj : listXJTEmerTunnel) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        //resultJson.put("listXJTEmerTunnel",listXJTEmerTunnel);


        //第三点：地道 T_EMER_UNDERGROUND_PASSAGE
        List<XJTEmerUndergroundPassage> listXJTEmerUndergroundPassage = xuJianApiService.getListXJTEmerUndergroundPassage();
        if (listXJTEmerUndergroundPassage != null && listXJTEmerUndergroundPassage.size() > 0) {
            //应急场所
            for (XJTEmerUndergroundPassage xj : listXJTEmerUndergroundPassage) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        //resultJson.put("listXJTEmerUndergroundPassage",listXJTEmerUndergroundPassage);


        //第四点：物资仓库 T_EMER_WARE_HOUSE


        //第五点：下立交 T_EMER_CONCAVE_INTERCHANGE
        List<XJTEmerConcaveInterChange> listXJTEmerConcaveInterChange = xuJianApiService.getListXJTEmerConcaveInterChange();
        if (listXJTEmerConcaveInterChange != null && listXJTEmerConcaveInterChange.size() > 0) {
            //应急场所
            for (XJTEmerConcaveInterChange xj : listXJTEmerConcaveInterChange) {
                if (StringUtil.isNotEmpty(xj.getLng())) {
                    target = new GlobalCoordinates(Double.parseDouble(xj.getLat()), Double.parseDouble(xj.getLng()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    xj.setMeter(meter);
                }


            }
        }
        //resultJson.put("listXJTEmerConcaveInterChange",listXJTEmerConcaveInterChange);

        resultJson.put("listXJTSheshi", listXJTEmerSubwayStation.size() + listXJTEmerTunnel.size() + listXJTEmerUndergroundPassage.size() + listXJTEmerConcaveInterChange.size());
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 公共安全模块-应急资源
     * teamgroupcount	应急队伍数量
     * reservepointcount	储备点数量
     * expertgroupcount	专家组数量
     * riskcount	危险源数量
     * refugecount	避难场所数量
     * casecount	案例库数量
     * plancount	预案库数量
     * repositorycount	知识库数量
     */
    @RequestMapping(value = "/getEmergencyResource")
    public void getEmergencyResource(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResource-----start-------");

        Long teamgroupcount = gongGongAnQuanApiService.getTeamGroupCount();
        resultJson.put("teamgroupcount", teamgroupcount);

        //储备点数量 reservepointcount lj_er_resource_goods 应急资源物资
        Long reservepointcount = gongGongAnQuanApiService.getReservepointcount();
        resultJson.put("reservepointcount", reservepointcount);

        //专家组数量 expertgroupcount lj_er_resource_experts
        Long expertgroupcount = gongGongAnQuanApiService.getxpertgroupcount();
        resultJson.put("expertgroupcount", expertgroupcount);


        //危险源数量 riskcount lj_er_danger
        Long riskcount = gongGongAnQuanApiService.getRiskcount();
        resultJson.put("riskcount", riskcount);


        //避难场所数量 refugecount  lj_er_resource_place
        Long refugecount = gongGongAnQuanApiService.getrefugecount();
        resultJson.put("refugecount", refugecount);


        //案例库数量 casecount lj_er_classical_case
        Long casecount = gongGongAnQuanApiService.getCasecount();
        resultJson.put("casecount", casecount);


        //预案库数量 plancount lj_er_reserve_plan
        Long plancount = gongGongAnQuanApiService.getPlancount();
        resultJson.put("plancount", plancount);
        //知识库数量 repositorycount lj_er_common_sense
        Long repositorycount = gongGongAnQuanApiService.getRepositorycount();
        resultJson.put("repositorycount", repositorycount);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 公共安全模块-应急资源详情根据Type获取相关详情
     * 0	应急队伍列表
     * 1	储备点列表
     * 2	专家组列表
     * 3	危险源列表
     * 4	避难场所列表
     * 5	案例库列表
     * 6	预案库列表
     * 7	知识库列表
     */
    @RequestMapping(value = "/getEmergencyResourceDetail")
    public void getEmergencyResourceDetail(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getEmergencyResourceDetail-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        // 应急队伍数量
        String type = jsonObject.getString("type");
        if (type.equals("0")) {
            List<LjErResourceTeam> listLjErResourceTeam = gongGongAnQuanApiService.getListLjErResourceTeam();
            if (listLjErResourceTeam != null && listLjErResourceTeam.size() > 0) {
                resultJson.put("listLjErResourceTeam", listLjErResourceTeam);
            } else {
                resultJson.put("listLjErResourceTeam", "");
            }
        }
        //专家组数量
        if (type.equals("1")) {
            List<LjErResourceExperts> listLjErResourceExperts = gongGongAnQuanApiService.getListLjErResourceExperts();
            if (listLjErResourceExperts != null && listLjErResourceExperts.size() > 0) {
                resultJson.put("listLjErResourceExperts", listLjErResourceExperts);
            } else {
                resultJson.put("listLjErResourceExperts", "");
            }
        }
        //储备点数量
        if (type.equals("2")) {
            List<LjErResourceGoods> listLjErResourceGoods = gongGongAnQuanApiService.getListLjErResourceGoods();
            if (listLjErResourceGoods != null && listLjErResourceGoods.size() > 0) {
                for (LjErResourceGoods lj : listLjErResourceGoods) {
                    double[] map = MapUtil.bd09towgs84(Double.parseDouble(lj.getBaiduLongitude()), Double.parseDouble(lj.getBaiduLatitude()));
                    lj.setBaiduLongitude(map[0] + "");
                    lj.setBaiduLatitude(map[1] + "");
                }

                resultJson.put("listLjErResourceGoods", listLjErResourceGoods);
            } else {
                resultJson.put("listLjErResourceGoods", "");
            }
        }
        //危险源数量
        if (type.equals("3")) {
            List<LjErDanger> listLjErDanger = gongGongAnQuanApiService.getListLjErDanger();
            if (listLjErDanger != null && listLjErDanger.size() > 0) {
                for (LjErDanger lj : listLjErDanger) {
                    double[] map = MapUtil.bd09towgs84(Double.parseDouble(lj.getBaiduLongitude()), Double.parseDouble(lj.getBaiduLatitude()));
                    lj.setBaiduLongitude(map[0] + "");
                    lj.setBaiduLatitude(map[1] + "");
                }
                resultJson.put("listLjErDanger", listLjErDanger);
            } else {
                resultJson.put("listLjErDanger", "");
            }
        }
        //避难场所数量
        if (type.equals("4")) {
            List<LjErResourcePlace> listLjErResourcePlace = gongGongAnQuanApiService.getListLjErResourcePlace();
            if (listLjErResourcePlace != null && listLjErResourcePlace.size() > 0) {
                for (LjErResourcePlace lj : listLjErResourcePlace) {
                    double[] map = MapUtil.bd09towgs84(Double.parseDouble(lj.getBaiduLongitude()), Double.parseDouble(lj.getBaiduLatitude()));
                    lj.setBaiduLongitude(map[0] + "");
                    lj.setBaiduLatitude(map[1] + "");
                }
                resultJson.put("listLjErResourcePlace", listLjErResourcePlace);
            } else {
                resultJson.put("listLjErResourcePlace", "");
            }
        }

        //案例库数量
        if (type.equals("5")) {
            List<LjErClassicalCase> listLjErClassicalCase = gongGongAnQuanApiService.getListLjErClassicalCase();
            if (listLjErClassicalCase != null && listLjErClassicalCase.size() > 0) {
                resultJson.put("listLjErClassicalCase", listLjErClassicalCase);
            } else {
                resultJson.put("listLjErClassicalCase", "");
            }
        }

        //预案库数量
        if (type.equals("6")) {
            List<LjErReservePlan> listLjErReservePlan = gongGongAnQuanApiService.getListLjErReservePlan();
            if (listLjErReservePlan != null && listLjErReservePlan.size() > 0) {
                resultJson.put("listLjErReservePlan", listLjErReservePlan);
            } else {
                resultJson.put("listLjErReservePlan", "");
            }
        }

        //知识库数量
        if (type.equals("7")) {
            List<LjErCommonSense> listLjErCommonSense = gongGongAnQuanApiService.getListLjErCommonSense();
            if (listLjErCommonSense != null && listLjErCommonSense.size() > 0) {
                resultJson.put("listLjErCommonSense", listLjErCommonSense);
            } else {
                resultJson.put("listLjErCommonSense", "");
            }
        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 公共安全模块-Top5事件列表
     * hp_emergency_event
     */
    @RequestMapping(value = "/getTop5EventList")
    public void getTop5EventList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        // 创建HttpClient实例
        HttpClient client = HttpClientBuilder.create().build();
        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        JSONObject locationjson = null;
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getTop5EventList-----start-------");
        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEvent();
        String eventType = "";
        for (SysHpEmergencyEvent sysHpEmergencyEvent : listSysHpEmergencyEvent) {

            double[] map = MapUtil.bd09towgs84(Double.parseDouble(sysHpEmergencyEvent.getBaiduLongitude()), Double.parseDouble(sysHpEmergencyEvent.getBaiduLatitude()));
            sysHpEmergencyEvent.setBaiduLongitude(map[0] + "");
            sysHpEmergencyEvent.setBaiduLatitude(map[1] + "");


        }
        resultJson.put("listSysHpEmergencyEvent", listSysHpEmergencyEvent);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 公共安全模块-当年事件列表
     * hp_emergency_event
     */
    @RequestMapping(value = "/getTopYearEventList")
    public void getTopYearEventList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        // 创建HttpClient实例
        HttpClient client = HttpClientBuilder.create().build();

        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        JSONObject locationjson = null;
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getTopYearEventList-----start-------");
        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiSysDataService.getListSysHpEmergencyEvent20(DateUtil.getCurrYearFirst());
//        List<SysHpEmergencyEvent> listSysHpEmergencyEvent = gongGongAnQuanApiService.getListSysHpEmergencyEvent20(yeartime);
        String eventType = "";
        for (SysHpEmergencyEvent sysHpEmergencyEvent : listSysHpEmergencyEvent) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(sysHpEmergencyEvent.getBaiduLongitude()), Double.parseDouble(sysHpEmergencyEvent.getBaiduLatitude()));
            sysHpEmergencyEvent.setBaiduLongitude(map[0] + "");
            sysHpEmergencyEvent.setBaiduLatitude(map[1] + "");

            if (sysHpEmergencyEvent.getEventType().equals("290ef77a-7c02-41c1-a279-5e2ce0a45340")) {

                eventType = "事故灾难";

            } else if (sysHpEmergencyEvent.getEventType().equals("3d93e3d7-ba1d-4442-b825-44333b66290a")) {
                eventType = "其他";

            } else if (sysHpEmergencyEvent.getEventType().equals("1e1b5957-5818-4a0f-8f99-eb9ce46b3e51")) {
                eventType = "自然灾害";

            } else if (sysHpEmergencyEvent.getEventType().equals("348be4c1-46ea-47c1-a0c8-2c7175a7a890")) {
                eventType = "社会安全";

            } else if (sysHpEmergencyEvent.getEventType().equals("2b80b610-461c-4389-bf61-49ba17b85f0d")) {
                eventType = "公共卫生";

            }

            sysHpEmergencyEvent.setEventType(eventType);


        }
        resultJson.put("listSysHpEmergencyEvent", listSysHpEmergencyEvent);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 从req中读取数据
     *
     * @param req
     * @return
     */
    private String getRequestBodyString(HttpServletRequest req) {
        StringBuilder builder = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream(), "utf-8"));
            String line;
            while ((line = br.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            // e.printStackTrace();
            return null;
        }
        return builder.toString();
    }

    private void responseErrorData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        JSONObject resultObj = new JSONObject();
        resultObj.put("errorcode", 1);
        resultObj.put("message", string);
        responseData(resultObj.toString(), resp);
    }

    private void responseData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        responseDate("application/json;charset=UTF-8", string, resp);
    }

    private void responseDate(String contentType, String value, HttpServletResponse resp) throws Exception {
        resp.setContentType(contentType);
        resp.getWriter().write(value);
    }
}
